/*
    9. Write a program in C to find the largest element using Dynamic Memory Allocation. 
    Test Data :
    Input total number of elements(1 to 100): 5

    Number 1: 5
    Number 2: 7
    Number 3: 2
    Number 4: 9
    Number 5: 8
    Expected Output :

    The Largest element is :  9.00 
*/
#include <stdio.h>
#include <stdlib.h>

float maxnum(float *array, int len){
    int i = 1;
    float max = array[0];
    while(i < len){
        if(array[i] > max){
            max = array[i];
        }
        ++i;
    }
    return max;
}

int main(void){
    int len, max = 0;
    float *numArray = NULL;
    printf("Input totoal number of elements(1 to 100): ");
    scanf("%d", &len);
    numArray = (float *)malloc(len * sizeof(float));
    if(!numArray){
        printf("malloc failed!\n");
        return -1;
    }
    for(int i = 0; i < len; i++){
        printf("Number %d: ", i + 1);
        scanf("%f", &numArray[i]);
    }
    printf("The largest element is : %.2f\n", maxnum(numArray, len));
    free(numArray);

    return 0;
}
